package org.lzy.shop.adapter

import android.content.Context
import android.view.ViewGroup
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import org.lzy.shop.R
import org.lzy.shop.response.ItemMsg
import org.lzy.shop.util.setUrlRound

class CustomMsgAdapter: BaseQuickAdapter<ItemMsg, QuickViewHolder>()  {

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): QuickViewHolder {
        return QuickViewHolder(R.layout.item_custom_list, parent)
    }

    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: ItemMsg?) {
        item?.let {
            // 0-反馈(用户), 1-回复(客服)
            if (item.type==1) {
                holder.setText(R.id.msg_time, item.createTime)
                holder.setText(R.id.left_msg, item.content.data)
                holder.setText(R.id.other_username, item.adminUserName)
                setUrlRound(item.adminUserHeadImg, 80f, holder.getView(R.id.other_img))
                holder.setGone(R.id.left_layout, false)
                holder.setGone(R.id.right_layout, true)
            }else if(item.type==0) {
                holder.setText(R.id.msg_time, item.createTime)
                holder.setText(R.id.right_msg, item.content.data)
                holder.setText(R.id.user_txt, item.nickName)
                setUrlRound(item.avatarUrl,80f,holder.getView(R.id.user_img))
                holder.setGone(R.id.left_layout, true)
                holder.setGone(R.id.right_layout, false)
            }


        }




    }



}